/*
  获取相关参数
  sys - 系统版本号
  net - 网络情况（wifi/no_wifi 等）
  chn - 渠道标志（web的渠道标志全部以web开头，如web_remix）
  web - 标志web请求（取值2）
  ts - 时间戳（13位毫秒数）
*/
import { getDeviceInfo } from './mgtv'
import Cookies from 'js-cookie'
async function Mustparameter (obj) {
  const net = 'wifi'
  const ver = '1.0'
  let sys = Cookies.get('sys')
  let mod = Cookies.get('mod')
  let did = Cookies.get('did')
  const chn = 'touch_doll'
  const ts = new Date().getTime()
  if (!sys || !mod || !did) {
    try {
      const sysDev = await getDeviceInfo()
      sys = sysDev.sver || 'web'
      mod = sysDev.device || 'unknow'
      did = sysDev.did || ts
      Cookies.set('sys', sys)
      Cookies.set('mod', mod)
      Cookies.set('did', did)
    }
    catch (error) {
      console.log(error)
      sys = 'ios'
      mod = 'iphone'
      did = ts
    }
  }
  return {
    ver,
    sys,
    net,
    mod,
    did,
    ts,
    chn,
    web: 2,
    ...obj
  }
}

export default Mustparameter
